package com.ruoyi.project.im.lixian.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.im.lixian.domain.Lixian;
import com.ruoyi.project.im.lixian.service.ILixianService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 离线回复管理Controller
 * 
 * @author ruoyi
 * @date 2022-09-11
 */
@Controller
@RequestMapping("/im/lixian")
public class LixianController extends BaseController
{
    private String prefix = "im/lixian";

    @Autowired
    private ILixianService lixianService;

    @RequiresPermissions("im:lixian:view")
    @GetMapping()
    public String lixian()
    {
        return prefix + "/lixian";
    }

    /**
     * 查询离线回复管理列表
     */
    @RequiresPermissions("im:lixian:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Lixian lixian)
    {
        startPage();
        List<Lixian> list = lixianService.selectLixianList(lixian);
        System.out.println(list);
        return getDataTable(list);
    }

    /**
     * 导出离线回复管理列表
     */
    @RequiresPermissions("im:lixian:export")
    @Log(title = "离线回复管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Lixian lixian)
    {
        List<Lixian> list = lixianService.selectLixianList(lixian);
        ExcelUtil<Lixian> util = new ExcelUtil<Lixian>(Lixian.class);
        return util.exportExcel(list, "离线回复管理数据");
    }

    /**
     * 新增离线回复管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存离线回复管理
     */
    @RequiresPermissions("im:lixian:add")
    @Log(title = "离线回复管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Lixian lixian)
    {
        return toAjax(lixianService.insertLixian(lixian));
    }

    /**
     * 修改离线回复管理
     */
    @RequiresPermissions("im:lixian:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Lixian lixian = lixianService.selectLixianById(id);
        mmap.put("lixian", lixian);
        return prefix + "/edit";
    }

    /**
     * 修改保存离线回复管理
     */
    @RequiresPermissions("im:lixian:edit")
    @Log(title = "离线回复管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Lixian lixian)
    {
        return toAjax(lixianService.updateLixian(lixian));
    }

    /**
     * 删除离线回复管理
     */
    @RequiresPermissions("im:lixian:remove")
    @Log(title = "离线回复管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lixianService.deleteLixianByIds(ids));
    }
}
